from nonebot import on_command, CommandSession, get_bot
from nonebot.permission import SUPERUSER

bot = get_bot()

# 使用列表存储要发送消息的QQ群
group_ids = [529511125]  # 请替换为实际的QQ群号

# 使用变量存储要发送的消息
message_to_send = ''

# 定义开始群发命令
@on_command('开始群发',aliases=('我要群发','发送广告'),permission=SUPERUSER)
async def start_mass_sending(session: CommandSession):
    global message_to_send
    message_to_send = session.current_arg.strip()
    if not message_to_send:
        message_to_send = await session.aget('message', prompt='你想要发送什么消息？')
    for group_id in group_ids:
        try:
            await bot.send_group_msg(group_id=group_id, message=message_to_send)
        except Exception as e:
            print(f'Error sending message to group {group_id}: {e}')